import { Game, game } from "cc";
import { GameSocketClient } from "./GameSocketClient";
import ServerTimer from "./ServerTimer";
import { UserModel } from "../../hall/src/model/UserModel";

/**
 * socket 管理器
 */
export class GameSocketManager {

    private static _instance: GameSocketManager;

    private socketMap: Map<string, GameSocketClient> = new Map<string, GameSocketClient>();




    public static get instance(): GameSocketManager {
        if (!GameSocketManager._instance) {
            GameSocketManager._instance = new GameSocketManager();
            GameSocketManager._instance.init();
        }
        return GameSocketManager._instance;
    }

    private init() {

    }



    //获取 socketclient
    public getSocketClient(url: string): GameSocketClient {
        let client: GameSocketClient = null;
        if (this.socketMap.has(url)) {
            client = this.socketMap.get(url);
        }
        else {
            client = this.createSocketClient(url);
        }
        return client;
    }

    //创建 socketclient
    private createSocketClient(url: string) {
        let client: GameSocketClient = new GameSocketClient();
        client.init(url);
        return client;
    }
}